<?php

/**
 * Account.
 *
 * PHP version 8.3
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 */

/**
 * The Selling Partner API for Sellers.
 *
 * The [Selling Partner API for Sellers](https://developer-docs.amazon.com/sp-api/docs/sellers-api-v1-reference) (Sellers API) provides essential information about seller accounts, such as:  - The marketplaces a seller can list in - The default language and currency of a marketplace - Whether the seller has suspended listings  Refer to the [Sellers API reference](https://developer-docs.amazon.com/sp-api/docs/sellers-api-v1-reference) for details about this API's operations, data types, and schemas.
 *
 * The version of the OpenAPI document: v1
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.9.0
 */

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

namespace SpApi\Model\sellers\v1;

use SpApi\Model\ModelInterface;
use SpApi\ObjectSerializer;

/**
 * Account Class Doc Comment.
 *
 * @category Class
 *
 * @description The response schema for the &#x60;getAccount&#x60; operation.
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 *
 * @implements \ArrayAccess<string, mixed>
 */
class Account implements ModelInterface, \ArrayAccess, \JsonSerializable
{
    public const DISCRIMINATOR = null;

    public const BUSINESS_TYPE_CHARITY = 'CHARITY';
    public const BUSINESS_TYPE_CRAFTSMAN = 'CRAFTSMAN';
    public const BUSINESS_TYPE_NATURAL_PERSON_COMPANY = 'NATURAL_PERSON_COMPANY';
    public const BUSINESS_TYPE_PUBLIC_LISTED = 'PUBLIC_LISTED';
    public const BUSINESS_TYPE_PRIVATE_LIMITED = 'PRIVATE_LIMITED';
    public const BUSINESS_TYPE_SOLE_PROPRIETORSHIP = 'SOLE_PROPRIETORSHIP';
    public const BUSINESS_TYPE_STATE_OWNED = 'STATE_OWNED';
    public const BUSINESS_TYPE_INDIVIDUAL = 'INDIVIDUAL';
    public const SELLING_PLAN_PROFESSIONAL = 'PROFESSIONAL';
    public const SELLING_PLAN_INDIVIDUAL = 'INDIVIDUAL';

    /**
     * The original name of the model.
     */
    protected static string $openAPIModelName = 'Account';

    /**
     * Array of property to type mappings. Used for (de)serialization.
     *
     * @var string[]
     */
    protected static array $openAPITypes = [
        'marketplace_participation_list' => '\SpApi\Model\sellers\v1\MarketplaceParticipation[]',
        'business_type' => 'string',
        'selling_plan' => 'string',
        'business' => '\SpApi\Model\sellers\v1\Business',
        'primary_contact' => '\SpApi\Model\sellers\v1\PrimaryContact'];

    /**
     * Array of property to format mappings. Used for (de)serialization.
     *
     * @var string[]
     *
     * @phpstan-var array<string, string|null>
     *
     * @psalm-var array<string, string|null>
     */
    protected static array $openAPIFormats = [
        'marketplace_participation_list' => null,
        'business_type' => null,
        'selling_plan' => null,
        'business' => null,
        'primary_contact' => null];

    /**
     * Array of nullable properties. Used for (de)serialization.
     *
     * @var bool[]
     */
    protected static array $openAPINullables = [
        'marketplace_participation_list' => false,
        'business_type' => false,
        'selling_plan' => false,
        'business' => true,
        'primary_contact' => true,
    ];

    /**
     * If a nullable field gets set to null, insert it here.
     *
     * @var bool[]
     */
    protected array $openAPINullablesSetToNull = [];

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     *
     * @var string[]
     */
    protected static array $attributeMap = [
        'marketplace_participation_list' => 'marketplaceParticipationList',
        'business_type' => 'businessType',
        'selling_plan' => 'sellingPlan',
        'business' => 'business',
        'primary_contact' => 'primaryContact',
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     *
     * @var string[]
     */
    protected static array $setters = [
        'marketplace_participation_list' => 'setMarketplaceParticipationList',
        'business_type' => 'setBusinessType',
        'selling_plan' => 'setSellingPlan',
        'business' => 'setBusiness',
        'primary_contact' => 'setPrimaryContact',
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests).
     *
     * @var string[]
     */
    protected static array $getters = [
        'marketplace_participation_list' => 'getMarketplaceParticipationList',
        'business_type' => 'getBusinessType',
        'selling_plan' => 'getSellingPlan',
        'business' => 'getBusiness',
        'primary_contact' => 'getPrimaryContact',
    ];

    /**
     * Associative array for storing property values.
     */
    protected array $container = [];

    /**
     * Constructor.
     *
     * @param null|array $data Associated array of property values
     *                         initializing the model
     */
    public function __construct(?array $data = null)
    {
        $this->setIfExists('marketplace_participation_list', $data ?? [], null);
        $this->setIfExists('business_type', $data ?? [], null);
        $this->setIfExists('selling_plan', $data ?? [], null);
        $this->setIfExists('business', $data ?? [], null);
        $this->setIfExists('primary_contact', $data ?? [], null);
    }

    /**
     * Gets the string presentation of the object.
     *
     * @return string
     */
    public function __toString()
    {
        return json_encode(
            ObjectSerializer::sanitizeForSerialization($this),
            JSON_PRETTY_PRINT
        );
    }

    /**
     * Array of property to type mappings. Used for (de)serialization.
     */
    public static function openAPITypes(): array
    {
        return self::$openAPITypes;
    }

    /**
     * Array of property to format mappings. Used for (de)serialization.
     */
    public static function openAPIFormats(): array
    {
        return self::$openAPIFormats;
    }

    /**
     * Checks if a property is nullable.
     */
    public static function isNullable(string $property): bool
    {
        return self::openAPINullables()[$property] ?? false;
    }

    /**
     * Checks if a nullable property is set to null.
     */
    public function isNullableSetToNull(string $property): bool
    {
        return in_array($property, $this->getOpenAPINullablesSetToNull(), true);
    }

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     */
    public static function attributeMap(): array
    {
        return self::$attributeMap;
    }

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     */
    public static function setters(): array
    {
        return self::$setters;
    }

    /**
     * Array of attributes to getter functions (for serialization of requests).
     */
    public static function getters(): array
    {
        return self::$getters;
    }

    /**
     * The original name of the model.
     */
    public function getModelName(): string
    {
        return self::$openAPIModelName;
    }

    /**
     * Gets allowable values of the enum.
     *
     * @return string[]
     */
    public function getBusinessTypeAllowableValues(): array
    {
        return [
            self::BUSINESS_TYPE_CHARITY,
            self::BUSINESS_TYPE_CRAFTSMAN,
            self::BUSINESS_TYPE_NATURAL_PERSON_COMPANY,
            self::BUSINESS_TYPE_PUBLIC_LISTED,
            self::BUSINESS_TYPE_PRIVATE_LIMITED,
            self::BUSINESS_TYPE_SOLE_PROPRIETORSHIP,
            self::BUSINESS_TYPE_STATE_OWNED,
            self::BUSINESS_TYPE_INDIVIDUAL,
        ];
    }

    /**
     * Gets allowable values of the enum.
     *
     * @return string[]
     */
    public function getSellingPlanAllowableValues(): array
    {
        return [
            self::SELLING_PLAN_PROFESSIONAL,
            self::SELLING_PLAN_INDIVIDUAL,
        ];
    }

    /**
     * Show all the invalid properties with reasons.
     *
     * @return array invalid properties with reasons
     */
    public function listInvalidProperties(): array
    {
        $invalidProperties = [];

        if (null === $this->container['marketplace_participation_list']) {
            $invalidProperties[] = "'marketplace_participation_list' can't be null";
        }
        if (null === $this->container['business_type']) {
            $invalidProperties[] = "'business_type' can't be null";
        }
        $allowedValues = $this->getBusinessTypeAllowableValues();
        if (!is_null($this->container['business_type']) && !in_array($this->container['business_type'], $allowedValues, true)) {
            $invalidProperties[] = sprintf(
                "invalid value '%s' for 'business_type', must be one of '%s'",
                $this->container['business_type'],
                implode("', '", $allowedValues)
            );
        }

        if (null === $this->container['selling_plan']) {
            $invalidProperties[] = "'selling_plan' can't be null";
        }
        $allowedValues = $this->getSellingPlanAllowableValues();
        if (!is_null($this->container['selling_plan']) && !in_array($this->container['selling_plan'], $allowedValues, true)) {
            $invalidProperties[] = sprintf(
                "invalid value '%s' for 'selling_plan', must be one of '%s'",
                $this->container['selling_plan'],
                implode("', '", $allowedValues)
            );
        }

        return $invalidProperties;
    }

    /**
     * Validate all the properties in the model
     * return true if all passed.
     *
     * @return bool True if all properties are valid
     */
    public function valid(): bool
    {
        return 0 === count($this->listInvalidProperties());
    }

    /**
     * Gets marketplace_participation_list.
     */
    public function getMarketplaceParticipationList(): array
    {
        return $this->container['marketplace_participation_list'];
    }

    /**
     * Sets marketplace_participation_list.
     *
     * @param array $marketplace_participation_list list of marketplace participations
     */
    public function setMarketplaceParticipationList(array $marketplace_participation_list): self
    {
        if (is_null($marketplace_participation_list)) {
            throw new \InvalidArgumentException('non-nullable marketplace_participation_list cannot be null');
        }
        $this->container['marketplace_participation_list'] = $marketplace_participation_list;

        return $this;
    }

    /**
     * Gets business_type.
     */
    public function getBusinessType(): string
    {
        return $this->container['business_type'];
    }

    /**
     * Sets business_type.
     *
     * @param string $business_type the type of business registered for the seller account
     */
    public function setBusinessType(string $business_type): self
    {
        if (is_null($business_type)) {
            throw new \InvalidArgumentException('non-nullable business_type cannot be null');
        }
        $allowedValues = $this->getBusinessTypeAllowableValues();
        if (!in_array($business_type, $allowedValues, true)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value '%s' for 'business_type', must be one of '%s'",
                    $business_type,
                    implode("', '", $allowedValues)
                )
            );
        }
        $this->container['business_type'] = $business_type;

        return $this;
    }

    /**
     * Gets selling_plan.
     */
    public function getSellingPlan(): string
    {
        return $this->container['selling_plan'];
    }

    /**
     * Sets selling_plan.
     *
     * @param string $selling_plan the selling plan details
     */
    public function setSellingPlan(string $selling_plan): self
    {
        if (is_null($selling_plan)) {
            throw new \InvalidArgumentException('non-nullable selling_plan cannot be null');
        }
        $allowedValues = $this->getSellingPlanAllowableValues();
        if (!in_array($selling_plan, $allowedValues, true)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value '%s' for 'selling_plan', must be one of '%s'",
                    $selling_plan,
                    implode("', '", $allowedValues)
                )
            );
        }
        $this->container['selling_plan'] = $selling_plan;

        return $this;
    }

    /**
     * Gets business.
     */
    public function getBusiness(): ?Business
    {
        return $this->container['business'];
    }

    /**
     * Sets business.
     *
     * @param null|Business $business business
     */
    public function setBusiness(?Business $business): self
    {
        if (is_null($business)) {
            array_push($this->openAPINullablesSetToNull, 'business');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('business', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['business'] = $business;

        return $this;
    }

    /**
     * Gets primary_contact.
     */
    public function getPrimaryContact(): ?PrimaryContact
    {
        return $this->container['primary_contact'];
    }

    /**
     * Sets primary_contact.
     *
     * @param null|PrimaryContact $primary_contact primary_contact
     */
    public function setPrimaryContact(?PrimaryContact $primary_contact): self
    {
        if (is_null($primary_contact)) {
            array_push($this->openAPINullablesSetToNull, 'primary_contact');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('primary_contact', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['primary_contact'] = $primary_contact;

        return $this;
    }

    /**
     * Returns true if offset exists. False otherwise.
     *
     * @param int $offset Offset
     */
    public function offsetExists($offset): bool
    {
        return isset($this->container[$offset]);
    }

    /**
     * Gets offset.
     *
     * @param int $offset Offset
     *
     * @return null|mixed
     */
    #[\ReturnTypeWillChange]
    public function offsetGet($offset): mixed
    {
        return $this->container[$offset] ?? null;
    }

    /**
     * Sets value based on offset.
     *
     * @param null|int $offset Offset
     * @param mixed    $value  Value to be set
     */
    public function offsetSet($offset, mixed $value): void
    {
        if (is_null($offset)) {
            $this->container[] = $value;
        } else {
            $this->container[$offset] = $value;
        }
    }

    /**
     * Unsets offset.
     *
     * @param int $offset Offset
     */
    public function offsetUnset($offset): void
    {
        unset($this->container[$offset]);
    }

    /**
     * Serializes the object to a value that can be serialized natively by json_encode().
     *
     * @see https://www.php.net/manual/en/jsonserializable.jsonserialize.php
     *
     * @return mixed returns data which can be serialized by json_encode(), which is a value
     *               of any type other than a resource
     */
    #[\ReturnTypeWillChange]
    public function jsonSerialize(): mixed
    {
        return ObjectSerializer::sanitizeForSerialization($this);
    }

    /**
     * Gets a header-safe presentation of the object.
     */
    public function toHeaderValue(): string
    {
        return json_encode(ObjectSerializer::sanitizeForSerialization($this));
    }

    /**
     * Array of nullable properties.
     */
    protected static function openAPINullables(): array
    {
        return self::$openAPINullables;
    }

    /**
     * Array of nullable field names deliberately set to null.
     *
     * @return bool[]
     */
    private function getOpenAPINullablesSetToNull(): array
    {
        return $this->openAPINullablesSetToNull;
    }

    /**
     * Setter - Array of nullable field names deliberately set to null.
     *
     * @param bool[] $openAPINullablesSetToNull
     */
    private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void
    {
        $this->openAPINullablesSetToNull = $openAPINullablesSetToNull;
    }

    /**
     * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName
     * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the
     * $this->openAPINullablesSetToNull array.
     *
     * @param mixed $defaultValue
     */
    private function setIfExists(string $variableName, array $fields, $defaultValue): void
    {
        if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) {
            $this->openAPINullablesSetToNull[] = $variableName;
        }

        $this->container[$variableName] = $fields[$variableName] ?? $defaultValue;
    }
}
